<%--
    增加/修改请求
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="j" uri="j/tags" %>
<%@ taglib prefix="st" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<st:form formId="frmRequest" action="?act=saver">

    <input type="hidden" name="requestId" value="<j:des data="${d.requestId}"/>"/>
    <table class="layout">
        <colgroup>
            <col style="width:100px"/>
            <col/>
        </colgroup>
        <tr>
            <th>请求名称:</th>
            <td>
                <input type="text" name="requestName" value="${d.requestName}" placeholder="请求说明性内容..."/>
            </td>
        </tr>
        <tr>
            <th>所属模块：</th>
            <td>
                <select id="functionId" name="functionId" class="easyui-combotree" style="width:200px;"
                        data-options="url:'/user/center?act=menu',value:'<j:des data="${d.functionId}"/>',onSelect:functionTreeSelect"></select>
            </td>
        </tr>
        <tr>
            <th>检测模块权限:</th>
            <td>
                <input type="checkbox" name="checkFunctionPrivilege" <c:if test="${d.checkFunctionPrivilege}">checked</c:if> />
            </td>
        </tr>
        <tr>
            <th>所属操作:</th>
            <td>
                <select id="ddlActions" name="actionId">
                    <option>先选模块，再选操作...</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>请求类型:</th>
            <td>
                <select name="requestType">
                    <option value="get" <c:if test="${d.requestType eq 'get'}">selected="selected" </c:if>>get</option>
                    <option value="post" <c:if test="${d.requestType eq 'post'}">selected="selected" </c:if>>post</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>响应处理方式:</th>
            <td>
                <select name="responseType" onchange="responseTypeChanged(this);">
                    <option value="forward" <c:if test="${d.responseType eq 'forward'}">selected="selected" </c:if>>forward</option>
                    <option value="only_forward" <c:if test="${d.responseType eq 'only_forward'}">selected="selected" </c:if>>only_forward</option>
                    <option value="redirect" <c:if test="${d.responseType eq 'redirect'}">selected="selected" </c:if>>redirect</option>
                    <option value="json" <c:if test="${d.responseType eq 'json'}">selected="selected" </c:if>>json</option>
                    <option value="ajax" <c:if test="${d.responseType eq 'ajax'}">selected="selected" </c:if>>ajax</option>
                    <option value="tree" <c:if test="${d.responseType eq 'tree'}">selected="selected" </c:if>>tree</option>
                    <option value="datagrid" <c:if test="${d.responseType eq 'datagrid'}">selected="selected" </c:if>>datagrid</option>
                    <option value="form_i" <c:if test="${d.responseType eq 'form_i'}">selected="selected" </c:if>>form_iframe</option>
                    <option value="default" <c:if test="${d.responseType eq 'default'}">selected="selected" </c:if>>default</option>
                </select>
            </td>
        </tr>
        <tbody id="tbodyUrl">
            <tr>
                <th>URL</th>
                <td>
                    <input type="text" name="url" value="${d.url}" placeholder="forward:jsp;redirect:url" style="width:350px;"/>
                </td>
            </tr>
        </tbody>
        <tbody id="tbodyUsedGeneralService">

            <tr>
                <th>是否记录日志:</th>
                <td>
                    <input type="checkbox" name="logSupported" <c:if test="${d.logSupported}">checked</c:if> />
                </td>
            </tr>
            <tr>
                <th>使用通用业务类:</th>
                <td>
                    <input type="checkbox" id="chkUsedGeneralService" name="usedGeneralService" onchange="usedGSChanged(this);" <c:if test="${d.usedGeneralService}">checked</c:if> />
                </td>
            </tr>
        </tbody>
        <tbody id="tbodyNoUsedGS">
            <tr>
                <th>Bean类名:</th>
                <td>
                    <input type="text" name="beanClassName" value="${d.beanClassName}" style="width:300px;" placeholder="包名+类名，注意拼写"/>
                </td>
            </tr>
            <tr>
                <th>Bean方法名:</th>
                <td>
                    <input type="text" name="beanClassMethodName" value="${d.beanClassMethodName}" style="width:200px;" placeholder="仅方法名即可，不需要方法签名"/>
                </td>
            </tr>
        </tbody>
        <tbody id="tbodyUsedGS" style="display: none;">
            <tr>
                <th>操作类型:</th>
                <td>
                    <select name="generalAction">
                        <option value="allInOne" <c:if test="${d.generalAction eq 'allInOne'}">selected="selected" </c:if>>allInOne</option>
                        <option value="edit" <c:if test="${d.generalAction eq 'edit'}">selected="selected" </c:if>>edit</option>
                        <option value="save" <c:if test="${d.generalAction eq 'save'}">selected="selected" </c:if>>save</option>
                        <option value="delete " <c:if test="${d.generalAction eq 'delete '}">selected="selected" </c:if>>delete </option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>主键生成器KEY:</th>
                <td>
                    <input type="text" name="entityPkGenerateKey" value="${d.entityPkGenerateKey}" style="width:100px;" maxlength="3" placeholder="sys_table_pk_generator的主键，3字符长度"/>
                </td>
            </tr>
            <tr>
                <th>实体类:</th>
                <td>
                    <input type="text" name="entityClassName" value="${d.entityClassName}" style="width:300px;" placeholder="包名+类名，注意拼写"/>
                </td>
            </tr>
            <tr>
                <th>实体类触发器:</th>
                <td>
                    <input type="text" name="entityTrigger" value="${d.entityTrigger}" style="width:200px;" placeholder="触发器包名+类名，注意拼写"/>
                </td>
            </tr>
        </tbody>
    </table>
    <script>
        var actionId;
        $(function(){
           var fid = "<j:des data="${d.functionId}"/>";
            initActionSelect(fid);
            actionId = "${d.actionId}";
            window.setTimeout("setActionId()",300);

        });
        function setActionId(){
            $("#ddlActions").val(actionId);
        }
        function usedGSChanged(sender){
            if(sender.checked){
                $("#tbodyNoUsedGS").css("display","none");
                $("#tbodyUsedGS").css("display","");
            }else{
                $("#tbodyNoUsedGS").css("display","");
                $("#tbodyUsedGS").css("display","none");
            }
        }
        function functionTreeSelect(node){
            initActionSelect(node.id);
        }
        function initActionSelect(moduID){
            $.get("?act=getfactions",{fid:moduID},function(data){
                var $actions = $("#ddlActions");
                $actions.empty();
                var li = "<option value=''>若需要操作权限，请选择操作...</option>";
                $(li).appendTo($actions);
                var actions = Http.parseJSON(data);
                if(actions.length>0){
                    $(actions).each(function(i,item){
                        li = "<option value='"+item.actionId+"'>"+item.name+"</option>";
                        $(li).appendTo($actions);
                    });
                }
                if(''!='${d.actionId}'){
                    $actions.val("");
                }
            });
        }
        function responseTypeChanged(sender){
            var val = sender.value;
            if(val == "redirect"){
                $("#tbodyUrl").css("display","");
                $("#tbodyUsedGeneralService").css("display","none");
                $("#tbodyNoUsedGS").css("display","none");
                $("#tbodyUsedGS").css("display","none");
                $("#chkUsedGeneralService").attr("checked",false);
            }else if(val=="form_i" || val == "json"||val == "tree"||val=="default"||val =="datagrid"){
                $("#tbodyUsedGeneralService").css("display","");
                $("#tbodyNoUsedGS").css("display","");
                $("#tbodyUsedGS").css("display","none");
                $("#chkUsedGeneralService").attr("checked",false);
                $("#tbodyUrl").css("display","none");
            }else if(val == "only_forward"){
                //仅转发
                $("#tbodyUrl").css("display","");
                $("#tbodyUsedGeneralService").css("display","none");
                $("#tbodyNoUsedGS").css("display","none");
                $("#tbodyUsedGS").css("display","none");
                $("#chkUsedGeneralService").attr("checked",false);
            }else{
                //forward
                $("#tbodyUrl").css("display","");
                $("#tbodyUsedGeneralService").css("display","");
                $("#tbodyNoUsedGS").css("display","none");
                $("#tbodyUsedGS").css("display","");
                $("#chkUsedGeneralService").attr("checked",true);
            }
        }

        <c:if test="${d.usedGeneralService}">
            usedGSChanged(document.getElementById("chkUsedGeneralService"));
        </c:if>
    </script>
</st:form>
